package com.test.controller;

import com.test.bo.OrderBO;
import com.test.bo.PageDataBO;
import com.test.config.ConfigTest;
import com.test.entity.Order;
import com.test.service.OrderService;
import com.test.util.BaseResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/test")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/add")
    public BaseResponse add(@RequestBody Order order) {
        return BaseResponse.getBaseResponseSuccess(orderService.create(order));
    }

    @PostMapping("/update")
    public BaseResponse update(@RequestBody Order order) {
        Map paraMap = new HashMap();
        paraMap.put("orderTime", order.getOrderTime());
        paraMap.put("id", order.getId());
        paraMap.put("name", order.getName());
        paraMap.put("userName", order.getUserName());
        return BaseResponse.getBaseResponseSuccess(orderService.update(paraMap));
    }

    @PostMapping("/delete")
    public BaseResponse delete(@RequestBody Order order) {
        Map paraMap = new HashMap();
        paraMap.put("orderTime", order.getOrderTime());
        paraMap.put("id", order.getId());
        paraMap.put("name", order.getName());
        paraMap.put("userName", order.getUserName());
        return BaseResponse.getBaseResponseSuccess(orderService.delete(paraMap));
    }

    @PostMapping("/select")
    public BaseResponse select(@RequestBody Order order) {
        Map paraMap = new HashMap();
        paraMap.put("orderTime", order.getOrderTime());
        paraMap.put("id", order.getId());
        paraMap.put("name", order.getName());
        paraMap.put("userName", order.getUserName());
        return BaseResponse.getBaseResponseSuccess(orderService.detail(paraMap));
    }


    @PostMapping("/selectList")
    public BaseResponse selectList(@RequestBody PageDataBO<OrderBO> pageDataBO) {

        return BaseResponse.getBaseResponseSuccess(orderService.query(pageDataBO));
    }
    @Autowired
    private ConfigTest configTest;

    @PostMapping("/page")
    public BaseResponse selectList() {

        return BaseResponse.getBaseResponseSuccess(configTest.getName());
    }


}
